<?php

namespace app\controller\admin;

use app\base\BaseEncryptController;
use app\model\agency\AgencyOrderItemModel;
use app\model\agency\AgencyOrderModel;
use think\Request;

/**
 * AgentOrder 代理商进货单
 * Class AgentOrder
 * @package app\controller
 */
class AgencyOrder extends BaseEncryptController
{
    protected function initialize()
    {
        parent::initialize();
        $this->model = new AgencyOrderModel();
    }

    /**
     * 分页列表
     * @param string $handle_status
     * @param string $keyword
     * @param int $page
     * @param int $limit
     * @return \think\response\Json
     */
    public function getPage($handle_status = '', $keyword = '', $page = 1, $limit = 10)
    {
        $data = $this->model->getPageData($handle_status, $keyword, $page, $limit);
        return self::returnMsg(1, [
            'totalCount' => $data['total'],
            'currentPage' => $data['current'],
            'pageList' => $data['dataList']
        ]);
    }

    /**
     * 处理状态
     * @param Request $request
     * @return \think\response\Json
     */
    public function onOrderStatus(Request $request)
    {
        $id = $request->param('id');
        $remark = $request->param('remark');
        $handle_status = $request->param('handle_status');
        $return_data = $this->model->checkOrder($id, $handle_status, $this->currentUser['user_id'], $remark);
        return self::returnMsg($return_data['code'], $return_data['msg']);
    }

    /**
     * 获取订单详情
     * @param Request $request
     * @return \think\response\Json
     */
    public function onOrderInfo(Request $request)
    {
        $id = $request->param('id');
        $order_data = $this->model->getInfo($id);
        $order_item_model = new AgencyOrderItemModel();
        $items = $order_item_model->getItemsInfo($id);
        $order_data['items'] = $items;
        return self::returnMsg(1, $order_data);
    }


}
